package com.hjm.project.qyNotice.qyNotice.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.qyNotice.qyNotice.domain.qyNotice;
import com.hjm.project.qyNotice.qyNotice.service.INoticeService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 企业公告Controller
 * 
 * @author LOVE
 * @date 2020-11-28
 */
@Controller
@RequestMapping("/qyNotice/qyNotice")
public class QyNoticeController extends BaseController
{
    private String prefix = "qyNotice/qyNotice";

    @Autowired
    private INoticeService noticeService;

    @RequiresPermissions("qyNotice:qyNotice:view")
    @GetMapping()
    public String qyNotice()
    {
        return prefix + "/qyNotice";
    }

    /**
     * 查询企业公告列表
     */
    @RequiresPermissions("qyNotice:qyNotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(qyNotice notice)
    {
        startPage();
        List<qyNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 导出企业公告列表
     */
    @RequiresPermissions("qyNotice:qyNotice:export")
    @Log(title = "企业公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(qyNotice notice)
    {
        List<qyNotice> list = noticeService.selectNoticeList(notice);
        ExcelUtil<qyNotice> util = new ExcelUtil<qyNotice>(qyNotice.class);
        return util.exportExcel(list, "qyNotice");
    }

    /**
     * 新增企业公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业公告
     */
    @RequiresPermissions("qyNotice:qyNotice:add")
    @Log(title = "企业公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(qyNotice notice)
    {
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改企业公告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        qyNotice notice = noticeService.selectNoticeById(id);
        mmap.put("notice", notice);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业公告
     */
    @RequiresPermissions("qyNotice:qyNotice:edit")
    @Log(title = "企业公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(qyNotice notice)
    {
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除企业公告
     */
    @RequiresPermissions("qyNotice:qyNotice:remove")
    @Log(title = "企业公告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(noticeService.deleteNoticeByIds(ids));
    }
}
